package com.tarena.lbs.user.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.user.dao.mapper.UserGroupMapper;
import com.tarena.lbs.user.dao.repository.UserGroupRepository;
import com.tarena.lbs.user.pojo.po.UserGroupPO;
import com.tarena.lbs.user.pojo.query.UserGroupQuery;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class UserGroupRepositoryImpl implements UserGroupRepository {

    @Autowired
    private UserGroupMapper userGroupMapper;

    @Override
    public void save(UserGroupPO po) {
        log.info("保存人群数据:{}",po);
        userGroupMapper.insert(po);
    }


    @Override
    public List<UserGroupPO> getUserGroups(UserGroupQuery  query) {
        QueryWrapper<UserGroupPO> queryWrapper = new QueryWrapper<>();
        if (query.getGroupName() != null){
            queryWrapper.like("group_name", query.getGroupName());
        }
        queryWrapper.eq("business_id", query.getBusinessId());
        //select * from lbs_user_group where business_id=#{}
        return userGroupMapper.selectList(queryWrapper);
    }

    @Override
    public void delete(Integer id) {
        userGroupMapper.deleteById(id);
    }
}
